/* 
 * Copyright 2012 Andrzej Jozwiak {Andr3y}
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.example.project_hemo;

import roboguice.activity.RoboFragmentActivity;
import roboguice.inject.ContentView;
import android.content.Intent;
import android.os.Bundle;

/**
 * @author Andr3y
 */
@ContentView(R.layout.activity_measurement_list)
public class MeasurementListActivity extends RoboFragmentActivity 
    implements MeasurementListFragment.Callbacks {

    // Whether or not we are in dual-pane mode
    private boolean mIsTwoPane;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (findViewById(R.id.measurement_detail_container) != null) {
            mIsTwoPane = true;
            ((MeasurementListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.measurement_list))
                    .setActivateOnItemClick(true);
        }
    }

    @Override
    public void onItemSelected(String id) {
        if (mIsTwoPane) {
            Bundle arguments = new Bundle();
            arguments.putString(MeasurementDetailFragment.ARG_ITEM_ID, id);
            MeasurementDetailFragment fragment = new MeasurementDetailFragment();
            fragment.setArguments(arguments);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.measurement_detail_container, fragment)
                    .commit();

        } else {
            Intent detailIntent = new Intent(this, MeasurementDetailActivity.class);
            detailIntent.putExtra(MeasurementDetailFragment.ARG_ITEM_ID, id);
            startActivity(detailIntent);
        }
    }
}
